package com.controller;

import java.util.Collection;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.dao.DepartmentDao;
import com.pojo.Department;

@Controller
public class departmentController {

	@Resource
	public DepartmentDao dao;

	@RequestMapping(value = "/getDepartmentList")
	public String getDepartmentList(Model model) {
		Collection<Department> depa = dao.getDepartmentList();
		// List<Department> depa = dao.getDepartmentList();
		System.out.println(depa);
		model.addAttribute("depa", depa);
		System.out.println(555555);
		return "DepartmentManeger";
	}

	@RequestMapping(value = "/DepadeleteOne", method = RequestMethod.GET)
	/* @ResponseBody */
	public String deleteOne(@RequestParam int id) {
		System.out.println(id);
		Department depadelete = dao.deleteOne(id);
		System.out.println(depadelete);
		return "DepartmentManeger";

	}

	@RequestMapping(value = "/DepaupdateOne")
	public String updateOne(int id, Model model) {
		System.out.println(id);
		Department depaOne = new Department();
		depaOne = dao.updateOne(id);
		System.out.println(depaOne);
		model.addAttribute("depaOne", depaOne);
		System.out.println(444444);
		return "Departmentupdate";

	}

	@PostMapping(value = "/Depaupdate")
	public String update(Department department) {
		System.out.println(department);
		int up = dao.update(department);
		System.out.println(up);
		return "forward:/getDepartmentList";
	}

	@RequestMapping(value = "/DepaAddOneht")
	public String DepaAddOneht() {
		return "DepaAddOne";

	}

	@RequestMapping(value = "/DepaAddOne")
	public String DepaAddOne(Department department) {
		System.out.println(department);
		int add = dao.DepaAddOne(department);
		System.out.println(add);
		return "forward:/getDepartmentList";

	}
	/*
	 * ======= return "DepartmentManeger"; } >>>>>>>
	 * 5b179dda4a8a48366f4069b1a897e6f4b032eb23
	 */
}
